var app = getApp()
Page({
  data: {
    address: [],
    userInfo: {},
    //图标列表
    icons: [
      {
        id: 0,
        name: "待付款图标",
        src: "../../../images/ps_page/payment.png"
      },
      {
        id: 1,
        name: "等待发货图标",
        src: "../../../images/ps_page/send.png"
      },
      {
        id: 2,
        name: "待收货图标",
        src: "../../images/ps_page/delivered.png"
      },
      {
        id: 3,
        name: "待评价图标",
        src: "../../../images/ps_page/comment.png"
      },
      {
        id: 4,
        name: "退款／售后图标",
        src: "../../../images/ps_page/refund.png"
      },
  
    ],
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  onLoad: function () {
    if (app.globalData.userInfo) {
      console.log(app.globalData.userInfo)
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    console.log(e)
    if (e.detail.errMsg != 'getUserInfo:ok') {
      wx.showModal({
        title: '提示',
        content: '您点击了拒绝授权，将无法显示个人信息',
        showCancel: false,
        confirmText:'知道了'
      })
    } else {
      wx.login({
        success: function (res) {
          console.log(res)
          var code = res.code;
        }
      })
      app.globalData.userInfo = e.detail.userInfo
      console.log(app.globalData.userInfo)
      this.setData({
        userInfo: e.detail.userInfo,
        hasUserInfo: true
      })
    }

  },

  chooseAddress: function () {
    //TODO
    wx.navigateTo({
      url: '/pages/address_list/address_list',
    })
  },
  navigateToOrder: function (e) {
    var status = e.currentTarget.dataset.status;
    console.log("ps status" + status);
    var that = this;
    wx.switchTab({
      url: '/pages/order_list/order_list',
    })
    app.globalData.tab_id = status;
    console.log(app.globalData.tab_id);
  },
  logout: function () {
    wx.navigateTo({
      url: '../../admin/login/login'
    });
  },
  navigateToSavedItems: function () {
    wx.navigateTo({
      url: '/pages/personal_center/saved_items/saved_items'
    });
  },
  navigateToSavedShop: function () {
    wx.navigateTo({
      url: '/pages/personal_center/saved_shop/saved_shop'
    });
  },
  navigateToRecord: function () {
    wx.navigateTo({
      url: '/pages/personal_center/record/record'
    });
  },
  /**进入售后列表 */
  navigateToRefund: function (e) {
    wx.navigateTo({
      url: '/pages/customer_service/service_list/service_list',
    })
  }
})